﻿@inherits BaseComponent
<div id="@ElementId" class="@ClassNames" style="@StyleNames" @attributes="@Attributes">
    @ChildContent
    @foreach ( var snackbarInfo in snackbarInfos )
    {
        <Snackbar @key="@snackbarInfo.Key"
                  Key="@snackbarInfo.Key"
                  Visible="@snackbarInfo.Visible"
                  Color="@snackbarInfo.Color"
                  Multiline="@Multiline"
                  Interval="@(snackbarInfo.IntervalBeforeClose ?? Constants.DefaultIntervalBeforeClose)"
                  DelayCloseOnClick="@DelayCloseOnClick"
                  DelayCloseOnClickInterval="@DelayCloseOnClickInterval"
                  Closed="@(async (e)=> await OnSnackbarClosed(e.Key, e.CloseReason))">
            @if ( snackbarInfo.Title != null )
            {
                <SnackbarHeader>
                    @snackbarInfo.Title

                    @if ( snackbarInfo.ShowCloseButton )
                    {
                        var closeButtonText = snackbarInfo.CloseButtonText ?? CloseButtonText;
                        var closeButtonIcon = snackbarInfo.CloseButtonIcon ?? CloseButtonIcon ?? IconName.Times;

                        var key = snackbarInfo.Key;

                        <SnackbarAction Clicked="@(async ( e ) => await OnSnackbarClosed( key, SnackbarCloseReason.UserClosed ))">
                            <Icon Name="@closeButtonIcon" />
                            @closeButtonText
                        </SnackbarAction>
                    }
                </SnackbarHeader>
            }
            <SnackbarBody>
                @if ( snackbarInfo.MessageTemplate != null )
                {
                    @snackbarInfo.MessageTemplate
                }
                else
                {
                    @snackbarInfo.Message
                }


                @if ( snackbarInfo.ShowActionButton )
                {
                    var actionButtonText = snackbarInfo.ActionButtonText ?? ActionButtonText;
                    var actionButtonIcon = snackbarInfo.ActionButtonIcon ?? ActionButtonIcon;

                    var key = snackbarInfo.Key;

                    <SnackbarAction Clicked="@(async (e)=> await OnSnackbarClosed(key, SnackbarCloseReason.UserClosed))">
                        @if ( actionButtonIcon != null )
                        {
                            <Icon Name="@actionButtonIcon" />
                        }
                        @actionButtonText
                    </SnackbarAction>
                }
            </SnackbarBody>
        </Snackbar>
    }
</div>